﻿using System;
using System.Globalization;
using Microsoft.Xna.Framework;

namespace XTengine.ComponentModel
{
    public class BoundingBoxConverter : TypeConverter<BoundingBox>
    {
        public override BoundingBox ConvertFrom(string value)
        {
            string[] splits = value.Split(',');

            if (splits.Length < 6)
                return default(BoundingBox);

            CultureInfo eng = new CultureInfo("en-US");

            BoundingBox result = new BoundingBox();
            result.Min.X = Single.Parse(splits[0], eng);
            result.Min.Y = Single.Parse(splits[1], eng);
            result.Min.Z = Single.Parse(splits[2], eng);

            result.Max.X = Single.Parse(splits[3], eng);
            result.Max.Y = Single.Parse(splits[4], eng);
            result.Max.Z = Single.Parse(splits[5], eng);

            return result;
        }

        public override string ConvertTo(BoundingBox value)
        {
            return value.Min.X + "," + value.Min.Y + "," + value.Min.Z + "," +
                   value.Max.X + "," + value.Max.Y + "," + value.Max.Z;
        }
    }
}